package com.zhangck.webService.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhangck.webDao.CustomerRepository;
import com.zhangck.webService.CustomerService;

import cn.itcast.crm.domain.Customer;

/** 
* @author 上午茶
* @version 创建时间：2018年6月2日 下午12:16:56 
* 类说明 
*/
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
	
	@Autowired
	private CustomerRepository customerRepository;
	
	
	@Override
	public List<Customer> findNoassociatedCustomer() {
		return customerRepository.findByFixedAreaIdIsNull();
	}

	@Override
	public List<Customer> findAssociatedFixedAreaCustomer(String fixedAreaid) {
		return customerRepository.findByFixedAreaId(fixedAreaid);
	}

	@Override
	public void associatedFixedAreaToCustomer(String customerStr,String nocustomerIds, String fixedAreaid) {
			String[] split = customerStr.split("-");
			String[] split2 = nocustomerIds.split("-");
			for (String string : split) {
				int parseInt = Integer.parseInt(string);
				customerRepository.findOne(parseInt).setFixedAreaId(fixedAreaid);
			}
			for (String string : split2) {
				int parseInt = Integer.parseInt(string);
				customerRepository.findOne(parseInt).setFixedAreaId(null);
			}
	}

	@Override
	public void CustomerSave(Customer customer) {
				customerRepository.save(customer);
	}

	@Override
	public Customer getCutomer(String telephone) {
		return customerRepository.getTelephone(telephone);
	}

	@Override
	public void UpdateCutomer(String telephone) {
		 customerRepository.updateTelephone(telephone);
	}

	@Override
	public Customer loginCutomer(String telephone, String password) {
		return customerRepository.findByTelephoneAndPass(telephone,password);
	}

	@Override
	public String getFixeArea(String address) {
		return customerRepository.findFixedAreaIdByAddress(address);
	}

	

}
